package TopN;
import org.apache.hadoop.io.WritableComparable;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;

// 1. 实现 Writable 接口
public class FlowBean implements WritableComparable<FlowBean> {
    //private long upFlow;
    //private long downFlow;
    //private long sumFlow;
    //private String id;
    private float loanAmnt;
    private float term;

    //2  反序列化时，需要反射调用空参构造函数
    public FlowBean() {
    }

    //3  序列化方法
    @Override
    public void write(DataOutput dataOutput) throws IOException {
        dataOutput.writeFloat(loanAmnt);
        dataOutput.writeFloat(term);

    }

    //4 反序列化方法
    //5 反序列化方法读顺序必须和写序列化方法的写顺序必须一致
    @Override
    public void readFields(DataInput dataInput) throws IOException {
        loanAmnt = dataInput.readFloat();
        term = dataInput.readFloat();
    }

    // 6 编写toString方法，方便后续打印到文本
    @Override
    public String toString() {
        return loanAmnt + "\t" + term ;
    }//

    public FlowBean(float loanAmnt, float term) {
        this.loanAmnt= loanAmnt;
        this.term = term;
    }

    public float getLoanAmnt() {
        return loanAmnt;
    }

    public void setLoanAmnt(float loanAmnt) {
        this.loanAmnt= loanAmnt;
    }

    public float getTerm() { return term; }

    public void setTerm(float term) { this.term= term; }

    public void set(float loanAmnt, float term) {
        this.loanAmnt = loanAmnt;
        this.term = term;
    }

    @Override
    public int compareTo(FlowBean o) {
        int result;
        result=Float.compare(o.getLoanAmnt(),this.loanAmnt);

        return result;
    }
}

